package ws.jdbc.concurrent.driver.sqlserver.tds.rpc;

import java.nio.ByteBuffer;
import ws.jdbc.concurrent.driver.sqlserver.tds.datatypes.TYPE_INFO;
import ws.jdbc.concurrent.driver.sqlserver.tds.datatypes.TYPE_VARLEN;
import ws.jdbc.concurrent.driver.sqlserver.tds.datatypes.TypeInfoVarLenType;

/**
 *
 * @author Wilson Santos, 36228 <wilson.santos@ua.pt>
 */
public class ParamMetaData {

  private byte statusFlags;
  private TYPE_INFO info;

  public ParamMetaData(byte statusFlags, byte varlentype, TYPE_VARLEN type_varlen) {
    this.statusFlags = statusFlags;
    this.info = new TypeInfoVarLenType(varlentype, type_varlen);
  }

  public ParamMetaData(byte statusFlags, byte varlentype, int type_varlen, byte[] collation) {
    this.statusFlags = statusFlags;
    this.info = new TypeInfoVarLenType(varlentype, type_varlen, collation);
  }

  public byte[] getBytes() {
    return ByteBuffer.allocate(size()).
            put((byte) 0).
            put(statusFlags).
            put(info.getBytes()).
            array();
  }

  public int size() {
    return 2 + info.size();
  }

  public TYPE_INFO getTypeInfo() {
    return info;
  }
}
